package Presentation;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.KeyStroke;

public class MenuBar extends JMenuBar{
	
	private JMenu systemMenu;
	private JMenu moviesMenu;
	private JMenu helpMenu;
	private JMenu adminMenu;
	private final MainFrame main;
	
	
	public MenuBar(final MainFrame main){
		super();
		this.main = main;
	    setLayout(new FlowLayout(0,5,5));
	    
	    systemMenu = new JMenu("System");
	    add(systemMenu);
	    
	    JMenuItem menuItem = new JMenuItem("Login");
	    menuItem.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent evt){
				main.showLoginPanel();	
			}
		});
	   //menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0));
	    systemMenu.add(menuItem);
	    
	    menuItem = new JMenuItem("Logout");
	    menuItem.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent evt){
				main.logout();
			}
		});	    
	    systemMenu.add(menuItem);
	    
	    menuItem = new JMenuItem("New User");
	    menuItem.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent evt){
				main.showUserPanel(null,"New User",true);				
			}
		});	    
	    systemMenu.add(menuItem);
	    
	    menuItem = new JMenuItem("Exit");
	    menuItem.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent evt){
				main.shutDown();			
			}
		});
	    systemMenu.add(menuItem);
	    
	    /*    Options     */
	    
	    moviesMenu = new JMenu("Movies");
	    moviesMenu.setEnabled(false);
	    add(moviesMenu);
	    
	    menuItem = new JMenuItem("Find Movie");
	    menuItem.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent evt){
				String s = (String)JOptionPane.showInputDialog(
	                    main,
	                    "Enter Movie Name:\n",	                    
	                    "Find Movie",
	                    JOptionPane.PLAIN_MESSAGE);

				main.findMovieByName(s);
			}
		});
	    
	    moviesMenu.add(menuItem);    
	    
	    // Help //
	    
	    helpMenu = new JMenu("Help");
	    helpMenu.setEnabled(false);
	    add(helpMenu);
	    
	    menuItem = new JMenuItem("About");
	    menuItem.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent evt){				
				JOptionPane.showMessageDialog(null, "You Are Using FriendSheep v1.0\nBy BashBash Software Solutions:\n  ->  Amsalem Gil\n  ->  Bril Eran\n  ->  Cohen Ron\n  ->  Levi Isahy\n  ->  Vaksman Udi\n  ->  Vanunu Nadav\nReleased: June 2008" ,
						"About" , JOptionPane.PLAIN_MESSAGE);
			}
		});
	    helpMenu.add(menuItem);
	    
	    //addAdminOptions();
	}
	
	public void openUserOptions(){
		moviesMenu.setEnabled(true);
		helpMenu.setEnabled(true);
	}
	
	public void addAdminOptions(){
	    
	    adminMenu = new JMenu("Administrator");
	    add(adminMenu);
	    JMenuItem menuItem = new JMenuItem("Add Movie");
	    menuItem.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent evt){
				main.showNewMoviePanel();
			}
		});
	    adminMenu.add(menuItem);
	    menuItem = new JMenuItem("Remove Movie");
	    menuItem.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent evt){

				
			}
		});
	    adminMenu.add(menuItem);
	    menuItem = new JMenuItem("Remove User");
	    menuItem.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent evt){
					
			}
		});
	    adminMenu.add(menuItem);
	}

}
